#include<stdio.h>
#include<string.h>
#include<sys/wait.h>
#include<stdlib.h>
#include<unistd.h>
#define maxn 20

int main(void){
	int fd[2];
	char buf1[maxn],buf2[maxn];
	pipe(fd);
  	int x=fork();
	if(x==-1) exit(-1);

	if(x==0){
	   sleep(2);
	
	   read(fd[0],buf2,maxn);
		
	   int len=strlen(buf2);

	   for(int l=0,r=len-1;l<r;l++,r--)
	   {
		char tmp=buf2[r];
		buf2[r]=buf2[l];
		buf2[l]=tmp;
	   }
	   write(fd[1],buf2,maxn);

	}
	else{
	   int status;
	   strcpy(buf1,"hello world\n");
	   printf("hello world\n");
	   write(fd[1],buf1,maxn);
	   wait(&status);
	   read(fd[0],buf1,maxn);

	   printf("%s\n",buf1);
	}

	return 0;
}
